class Reception < ActiveRecord::Base
  belongs_to :member
  validates_presence_of :member
  validates_presence_of :call_date

  def self.count_each_member
    sql = <<SQL
    select
    members.name as member_name,
    count(receptions.call_date) as reception_count
    from members
    left join receptions on members.id = receptions.member_id
    group by members.identifier
    order by reception_count desc
SQL
    find_by_sql(sql)
    
  end
end
